package com.cn.ribbon.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class TestService {

    @Autowired
    private RestTemplate restTemplate;

     @HystrixCommand(fallbackMethod = "errMessage")
    public String home(String name){
        return restTemplate.getForObject("http://test-service/home?name="+name,String.class);
     }

     /**
      * 添加一个断路器的方法，当后台应用停止服务后，即使与后台应用断离
      *
      *
      * */
     public String errMessage(String names){
        return names+",has error";
     }
}
